<template>
	<view>
		<view class="user-head" >
			<image :src="info.avatar" mode="aspectFill" class="user-avatar"></image>
			<view class="user-mobile" v-if="info.mobile">
				<view style="margin-bottom: 10rpx;">{{info.user_name ?  info.user_name : "暂无用户名"}}</view>
				<view>{{info.mobile}}</view>
			</view>
			<view class="user-mobile" v-if="!info.mobile" @tap="toLogin()">未登录</view>
		</view>
		
		<view class="user-menu" @tap="toPayOrder()" >
			<view class="user-menu-body" >
				<image src="https://jy-yyzj.oss-cn-shanghai.aliyuncs.com/jdbx/h5/user-menu1.png" mode="widthFix" class="user-menu-icon"></image>
				<view class="user-menu-txt" >待支付订单</view>
				<image src="https://jy-yyzj.oss-cn-shanghai.aliyuncs.com/jdbx/h5/user-menu-right.png" mode="widthFix" class="user-menu-right"></image>
			</view>
		</view>
		<view class="user-menu" @tap="toOrder()" >
			<view class="user-menu-body" >
				<image src="https://jy-yyzj.oss-cn-shanghai.aliyuncs.com/jdbx/h5/user-menu2.png" mode="widthFix" class="user-menu-icon"></image>
				<view class="user-menu-txt" >我的保单</view>
				<image src="https://jy-yyzj.oss-cn-shanghai.aliyuncs.com/jdbx/h5/user-menu-right.png" mode="widthFix" class="user-menu-right"></image>
			</view>
		</view>
		<view class="user-menu" @tap="toCompensation()" >
			<view class="user-menu-body" >
				<image src="../../static/Icon/zxlp.png" mode="widthFix" class="user-menu-icon"></image>
				<view class="user-menu-txt" >在线理赔</view>
				<image src="https://jy-yyzj.oss-cn-shanghai.aliyuncs.com/jdbx/h5/user-menu-right.png" mode="widthFix" class="user-menu-right"></image>
			</view>
		</view>
		<view class="user-menu" @tap="changepwd()" >
			<view class="user-menu-body user-menu-noborder" >
				<image src="../../static/Icon/xgmm.png" mode="widthFix" class="user-menu-icon"></image>
				<view class="user-menu-txt" >修改密码</view>
				<image src="https://jy-yyzj.oss-cn-shanghai.aliyuncs.com/jdbx/h5/user-menu-right.png" mode="widthFix" class="user-menu-right"></image>
			</view>
		</view>
		<view class="user-menu" @tap="changeuser_name()" >
			<view class="user-menu-body user-menu-noborder" >
				<image src="../../static/img/user_name.png" mode="widthFix" class="user-menu-icon" ></image>
				<view class="user-menu-txt" >修改用户名</view>
				<image src="https://jy-yyzj.oss-cn-shanghai.aliyuncs.com/jdbx/h5/user-menu-right.png" mode="widthFix" class="user-menu-right"></image>
			</view>
		</view>
		<view class="user-out-btn" v-if="info.mobile" @tap="outLogin" >退出登陆</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				info : {}
			}
		},
		onShow() {
			this.getData();
		},
		methods:{
			toOrder(){
				if(!this.info.mobile) {
					return uni.reLaunch({
						url:'/pages/login/login'
					})
				}
				uni.navigateTo({
					url:'/pages/order/order'
				})
			},
			getData(){
				uni.showLoading({
					mask:true,
					title:"数据加载中"
				})
				this.ajax('index/user',{
					success:(res) => {
						this.info = res.msg;
						console.log(this.info);
						uni.hideLoading()
					}
				});
			},
			toPayOrder(){
				if(!this.info.mobile) {
					return uni.reLaunch({
						url:'/pages/login/login'
					})
				}
				uni.navigateTo({
					url:'/pages/order/nopay'
				})
				
			},
			changepwd(){
				if(!this.info.mobile) {
					return uni.reLaunch({
						url:'/pages/login/login'
					})
				}
				uni.navigateTo({
					url:'/pages/index/changepwd'
				})
			},
			changeuser_name(){
				if(!this.info.mobile) {
					return uni.reLaunch({
						url:'/pages/login/login'
					})
				}
				uni.navigateTo({
					url:'/pages/index/changename'
				})
			},
			outLogin(){
				this.ajax('login/outLogin',{
					success:(res) => {
						this.toast('退出登录成功');
						setTimeout(()=>{
							uni.reLaunch({
								url:'/pages/login/login'
							})
						},1000)
					}
				});
			},
			toLogin(){
				if(!this.info.mobile) {
					uni.reLaunch({
						url:'/pages/login/login'
					})
				}
			},
			// 在线理赔
			toCompensation(){
				if(!this.info.mobile) {
					return uni.reLaunch({
						url:'/pages/login/login'
					})
				}
				uni.navigateTo({
					url:'/pages/order/loss'
				})
			}
			
		}
	}
</script>

<style>
	@import url("@/static/css/index/user.css");
</style>
